<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="cookielib-examples.html" />
<link rel="prev" href="default-cookie-policy-objects.html" />
<link rel="parent" href="module-cookielib.html" />
<link rel="next" href="cookielib-examples.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>18.22.5 Cookie Objects </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.22.4 defaultcookiepolicy Objects"
  href="default-cookie-policy-objects.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18.22 cookielib  "
  href="module-cookielib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.22.6 Examples"
  href="cookielib-examples.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="default-cookie-policy-objects.html">18.22.4 DefaultCookiePolicy Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-cookielib.html">18.22 cookielib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="cookielib-examples.html">18.22.6 Examples</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION00202250000000000000000"></a><a name="cookie-objects"></a>
<br>
18.22.5 Cookie Objects 
</h2>

<p>
<tt class="class">Cookie</tt> instances have Python attributes roughly corresponding
to the standard cookie-attributes specified in the various cookie
standards.  The correspondence is not one-to-one, because there are
complicated rules for assigning default values, because the
<code>max-age</code> and <code>expires</code> cookie-attributes contain equivalent
information, and because RFC 2109 cookies may be 'downgraded' by
<tt class="module">cookielib</tt> from version 1 to version 0 (Netscape) cookies.

<p>
Assignment to these attributes should not be necessary other than in
rare circumstances in a <tt class="class">CookiePolicy</tt> method.  The class does
not enforce internal consistency, so you should know what you're
doing if you do that.

<p>
<dl><dt><b><tt id='l2h-4405' xml:id='l2h-4405' class="member">version</tt></b></dt>
<dd>
Integer or <tt class="constant">None</tt>.  Netscape cookies have <tt class="member">version</tt> 0.
RFC 2965 and RFC 2109 cookies have a <code>version</code> cookie-attribute
of 1.  However, note that <tt class="module">cookielib</tt> may 'downgrade' RFC 2109
cookies to Netscape cookies, in which case <tt class="member">version</tt> is 0.
</dl>
<dl><dt><b><tt id='l2h-4406' xml:id='l2h-4406' class="member">name</tt></b></dt>
<dd>
Cookie name (a string).
</dl>
<dl><dt><b><tt id='l2h-4407' xml:id='l2h-4407' class="member">value</tt></b></dt>
<dd>
Cookie value (a string), or <tt class="constant">None</tt>.
</dl>
<dl><dt><b><tt id='l2h-4408' xml:id='l2h-4408' class="member">port</tt></b></dt>
<dd>
String representing a port or a set of ports (eg. '80', or '80,8080'),
or <tt class="constant">None</tt>.
</dl>
<dl><dt><b><tt id='l2h-4409' xml:id='l2h-4409' class="member">path</tt></b></dt>
<dd>
Cookie path (a string, eg. <code>'/acme/rocket_launchers'</code>).
</dl>
<dl><dt><b><tt id='l2h-4410' xml:id='l2h-4410' class="member">secure</tt></b></dt>
<dd>
True if cookie should only be returned over a secure connection.
</dl>
<dl><dt><b><tt id='l2h-4411' xml:id='l2h-4411' class="member">expires</tt></b></dt>
<dd>
Integer expiry date in seconds since epoch, or <tt class="constant">None</tt>.  See
also the <tt class="method">is_expired()</tt> method.
</dl>
<dl><dt><b><tt id='l2h-4412' xml:id='l2h-4412' class="member">discard</tt></b></dt>
<dd>
True if this is a session cookie.
</dl>
<dl><dt><b><tt id='l2h-4413' xml:id='l2h-4413' class="member">comment</tt></b></dt>
<dd>
String comment from the server explaining the function of this cookie,
or <tt class="constant">None</tt>.
</dl>
<dl><dt><b><tt id='l2h-4414' xml:id='l2h-4414' class="member">comment_url</tt></b></dt>
<dd>
URL linking to a comment from the server explaining the function of
this cookie, or <tt class="constant">None</tt>.
</dl>
<dl><dt><b><tt id='l2h-4415' xml:id='l2h-4415' class="member">rfc2109</tt></b></dt>
<dd>
True if this cookie was received as an RFC 2109 cookie (ie. the cookie
arrived in a <span class="mailheader">Set-Cookie:</span> header, and the value of the
Version cookie-attribute in that header was 1).  This attribute is
provided because <tt class="module">cookielib</tt> may 'downgrade' RFC 2109 cookies
to Netscape cookies, in which case <tt class="member">version</tt> is 0.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><b><tt id='l2h-4416' xml:id='l2h-4416' class="member">port_specified</tt></b></dt>
<dd>
True if a port or set of ports was explicitly specified by the server
(in the <span class="mailheader">Set-Cookie:</span> / <span class="mailheader">Set-Cookie2:</span> header).
</dl>
<dl><dt><b><tt id='l2h-4417' xml:id='l2h-4417' class="member">domain_specified</tt></b></dt>
<dd>
True if a domain was explicitly specified by the server.
</dl>
<dl><dt><b><tt id='l2h-4418' xml:id='l2h-4418' class="member">domain_initial_dot</tt></b></dt>
<dd>
True if the domain explicitly specified by the server began with a
dot (<code>'.'</code>).
</dl>

<p>
Cookies may have additional non-standard cookie-attributes.  These may
be accessed using the following methods:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4419' xml:id='l2h-4419' class="method">has_nonstandard_attr</tt></b>(</nobr></td>
  <td><var>name</var>)</td></tr></table></dt>
<dd>
Return true if cookie has the named cookie-attribute.
</dl>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4420' xml:id='l2h-4420' class="method">get_nonstandard_attr</tt></b>(</nobr></td>
  <td><var>name, default=<tt class="constant">None</tt></var>)</td></tr></table></dt>
<dd>
If cookie has the named cookie-attribute, return its value.
Otherwise, return <var>default</var>.
</dl>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4421' xml:id='l2h-4421' class="method">set_nonstandard_attr</tt></b>(</nobr></td>
  <td><var>name, value</var>)</td></tr></table></dt>
<dd>
Set the value of the named cookie-attribute.
</dl>

<p>
The <tt class="class">Cookie</tt> class also defines the following method:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4422' xml:id='l2h-4422' class="method">is_expired</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>now=<tt class="constant">None</tt></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
True if cookie has passed the time at which the server requested it
should expire.  If <var>now</var> is given (in seconds since the epoch),
return whether the cookie has expired at the specified time.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.22.4 defaultcookiepolicy Objects"
  href="default-cookie-policy-objects.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18.22 cookielib  "
  href="module-cookielib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.22.6 Examples"
  href="cookielib-examples.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="default-cookie-policy-objects.html">18.22.4 DefaultCookiePolicy Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-cookielib.html">18.22 cookielib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="cookielib-examples.html">18.22.6 Examples</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
